package service

import "fmt"

type SrvError struct {
	Code      SrvErrorType
	Msg       string
	Err       error
	Operation string
}

func newSrvError(code SrvErrorType, msg string, err error, operation string) *SrvError {
	return &SrvError{
		Code:      code,
		Msg:       msg,
		Err:       err,
		Operation: operation,
	}
}

func (e *SrvError) Error() string {
	return fmt.Sprintf("code: %d, msg: %s, error: %v, operation: %s", e.Code, e.Msg, e.Err, e.Operation)
}

type SrvErrorType int

const (
	CodeDatabaseError SrvErrorType = 101
	CodeCacheError    SrvErrorType = 102

	CodeInvalidObject SrvErrorType = 201
	CodeNotFound      SrvErrorType = 202
	CodeExist         SrvErrorType = 203
)
